<template>
	<div>
		<slot />
		<JsTan :initAttrs="initAttrs" :formResource="resource" />
	</div>
</template>

<script>
import jiess from '@/jiess';
export default {
	components: { JsTan: jiess.components.JsTan },
	data() {
		return {
			resource: jiess.resourceTan,
			initAttrs: {
				'close-on-click-modal': false,
				'lock-scroll': false
			}
		};
	},
	created() {
		//页面校验错误回调
		this.$root.$on('headerSet', this.headerSet);
		//列表的表头设置弹框
		this.$root.$on('validateError', this.validateError);
	},
	methods: {
		validateError(data) {
			const { label, placeholder, validateMessage } = data;
			let msg = null;
			if (label || placeholder) {
				msg = `${label || placeholder} 为 ${validateMessage}`;
			} else {
				msg = '填写错误！';
			}
			if (this.ui === 'element') {
				this.$message.warning(msg);
			} else {
				this.$Notice.warning({ title: msg });
			}
		},
		headerSet(tableContext) {
			this.$jiess.nodeTan.open({
				title: '表头设置',
				context: tableContext,
				pageConfig: {
					form: {
						paramKey: 'headerSet'
					}
				},
				buttons: [
					{
						innerHTML: '确定',
						type: 'primary',
						click: tableContext.sureSetTableHead
					}
				]
			});
		}
	}
};
</script>
